package erfgame.core.graphics.renderer.render;

import java.util.Arrays;

public class IncrementalAnimation implements Animation {

	private float[] progresses;
	private Render[] frames;
	
	public IncrementalAnimation( float[] progresses, Render[] frames ) {
		this.progresses = progresses;
		this.frames = frames;
	}
	
	public Render getFrame(float progress) {
		int position = Arrays.binarySearch(this.progresses, progress);
		if( position < 0 ) {
			position = -(position+1);
		} else {
			position--;
		}
		if( position >= progresses.length ) {
			position = progresses.length - 1;
		}
		return frames[position];
	}

}
